<?php

namespace Home\Controller;

use Home\Logic\TuserLogic;
use Think\Controller;

/**
 * @desc 权限登录检测
 * @author 张云江
 */
class InitController extends Controller
{
    /**
     * 初始化
     * @return boolean
     */
    protected function _initialize()
    {
        if (IS_GET) {
            \Mlog::info("request-GET:【" . CONTROLLER_NAME . '/' . ACTION_NAME . "】【user_id:" . $_COOKIE['order_uid'] . "】:" . json_encode($_GET, JSON_UNESCAPED_UNICODE));
        } else if (IS_POST) {
            \Mlog::info("request-POST【" . CONTROLLER_NAME . '/' . ACTION_NAME . "】【user_id:" . $_COOKIE['order_uid'] . "】:" . json_encode($_POST, JSON_UNESCAPED_UNICODE));
        }
        $login_time = $_COOKIE['order_login_time'];
        $dt_time = strtotime(date("Y-m-d H:i:s", time())) - strtotime($login_time);
        //判断是否有uid
        if (empty($_COOKIE['order_uid'])) {
            cookie('order_uid', null);
            cookie('order_login_name', null);
            cookie('order_nick_name', null);
            cookie('order_login_time', null);
            $this->error("当前用户未登录，请重新登录！", U('Index/index'));
        } else if (C('LOGIN_OUT_TIMECHECK') && $dt_time > C('LOGIN_OUT_TIME')) {
            unset($_COOKIE['order_login_time']);
            cookie('order_uid', null);
            cookie('order_login_name', null);
            cookie('order_nick_name', null);
            cookie('order_login_time', null);
            $this->error("当前用户登录超时，请重新登录！", U('Index/index'));
        } else {
            $GLOBALS["user"] = array(
                "order_uid" => "uid：" . $_COOKIE['order_uid'],
                "nick_name" => "姓名：" . $_COOKIE['order_login_name'],
                "datetime" => "当前时间：" . date("Y-m-d H:i:s", time())
            );
            cookie('order_login_time', date("Y-m-d H:i:s", time()));
        }
    }
}
